package com.cskaoyan.day1.collection;

import java.util.Arrays;

/**
 * @author Common-zhou
 * @since 2023-02-27 16:25
 */
public class CollectionDemo1 {
    public static void main(String[] args) {

        // 1.数组的长度 需要自己确定。
        // 2.对数组的增删改查 非常的麻烦


        Student[] students = new Student[5];

        students[0] = new Student("张三丰", 100);
        students[1] = new Student("张无忌", 24);
        students[2] = new Student("白猫鹰王", 50);
        students[3] = new Student("金毛狮王", 70);
        students[4] = new Student("东方不败", 20);

        //students[0] = null;

        System.out.println(Arrays.toString(students));

        for (int i = 0; i < students.length - 1; i++) {
            // i i+1
            students[i] = students[i + 1];
        }
        students[4] = null;


        System.out.println(Arrays.toString(students));


        // 张三丰  张无忌   白猫鹰王  金毛狮王  东方不败
        // 张无忌   白猫鹰王  金毛狮王  东方不败

        // bug: 代码实际运行的逻辑  和  自己以为的逻辑不符合
        // 解决bug的两种方式：
        // 1.打印  。        System.out.println();
        //     log.info();

        // 2.debug
        // 检查数据，

        // 新学期 又来了三个学生
        Student[] students1 = new Student[10];
        for (int i = 0; i < students.length - 1; i++) {
            students1[i] = students[i];
        }

        students1[4] = new Student("zs", 19);
        students1[5] = new Student("ls", 20);
        students1[6] = new Student("zl", 20);

        System.out.println(Arrays.toString(students1));


    }
}

class Student {
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + '}';
    }
}
